package com.tony.chartdemo;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.tony.chartdemo.fragment.BarChartFragment;
import com.tony.chartdemo.fragment.LineChartLegend;
import com.tony.chartdemo.fragment.PieChartFragment;

public class MainActivity extends AppCompatActivity {
    private FragmentManager fragmentManager;
    private Fragment fragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        fragmentManager = getSupportFragmentManager();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.chart_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        String title="LineChartLegend";
        switch (item.getItemId()) {
            case R.id.lineChart_legend:
                fragment = new LineChartLegend();
               title="LineChartLegend";
                break;

            case R.id.barChart_legend:
                fragment = new BarChartFragment();
                title="barChart";
                break;
            case R.id.pirChart:
                fragment = new PieChartFragment();
                title="PieChart";
                break;
            default:
                fragment = new LineChartLegend();
                break;
        }
        getSupportActionBar().setTitle(title);
        fragmentManager.beginTransaction().replace(R.id.frag_container, fragment).commit();
        return true;
    }


}
